/**@author Jason 吕建辉
 * @data 2018-04-07
 * @描述：模板组件采用 layui-2.2.6 操作手册可参考管饭文档
 */
//提取弹窗组件为公共
var layer;

layui.use(['layer', 'table'], function () {
    layer = layui.layer;
    var table = layui.table;
    table.render({
        id: 'jqGrid',
        elem: '#jqGrid',
        url: 'sys/generator/list',
        where: $('#searchFrom').containerJson(),
        method: 'get', //如果无需自定义HTTP类型，可不加该参数
        request: pageRequest,
        response: pageResponse,
        page: pagenation,
        cellMinWidth: 60,//全局定义常规单元格的最小宽度
        cols: [[
            {
                type: 'checkbox',
                fixed: 'left'
            },
            {
                field: 'tableName',
                title: '表名',
                align: 'center'
            }, {
                field: 'engine',
                title: 'Engine',
                align: 'center'
            }, {
                field: 'tableComment',
                title: '表备注',
                align: 'center'
            }, {
                field: 'createTime',
                title: '创建时间',
                align: 'center'
            }
        ]]
    });

    // 绑定操作
    var $2 = layui.$, active = {
        query: function () { //查询
            table.reload('jqGrid', {
                page: {curr: 1},
                where: $('#searchFrom').containerJson()
            });
            return false;
        },
        generator: function () {//生成代码

            var checkStatus = table.checkStatus('jqGrid');
            console.log(checkStatus);
            var data = checkStatus.data;
            var tables = [];
            $.each(data, function (i, v) {
                tables.push(v.tableName);
            });
            layer.alert(JSON.stringify(tables));
            location.href = "sys/generator/code?tables=" + JSON.stringify(tables);
        }
    };
    $2('.layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
        return false;
    });
});